<?php

use Yolo\Di\DI;
use Yolo\Errors\RpcException;
use Yolo\Rpc\Rpc;

if (!function_exists('get_rpc_response')) {

    /**
     * @return Rpc
     * @throws ReflectionException
     * @throws \Yolo\Di\Errors\CircularDependencyException
     * @throws \Yolo\Di\Errors\InvalidAttributeException
     * @throws \Yolo\Di\Errors\ParameterTypeEmptyException
     * @deprecated DO NOT use it, it will remove in the future
     */
    function get_rpc_response(): Rpc
    {
        return DI::use(Rpc::class);
    }
}

if (!function_exists('ok_response')) {

    /**
     * @return string[]
     * @deprecated use Rpc::ok() instead
     */
    function ok_response(): array
    {
        return Rpc::ok();
    }
}

if (!function_exists('error_response')) {

    /**
     * @param RpcException $e
     * @param array $metadata
     * @return RpcException
     * @deprecated DO NOT use it, it will remove in the future
     */
    function error_response(RpcException $e, array $metadata): RpcException
    {
        return Rpc::error($e, $metadata);
    }
}

if (!function_exists('list_response')) {

    /**
     * @param int $totalRows
     * @param array $data
     * @return array
     * @deprecated use Rpc::list() instead
     */
    function list_response(int $totalRows, array $data): array
    {
        return Rpc::list($totalRows, $data);
    }
}

if (!function_exists('rpc_error')) {

    /**
     * @param RpcException $e
     * @param array $responseMetadata
     * @return RpcException
     * @deprecated use Rpc::error() instead
     */
    function rpc_error(RpcException $e, array $responseMetadata = []): RpcException
    {
        $e->addResponseMetadata($responseMetadata);
        return $e;
    }
}
